<template>
  <div>
    <div class="Home_box">
      <div class="Home_list" v-for="(item,index) in cartItem" :key="index">
        <div class="home_check">
          <input type="checkbox" :checked="item.checked" @click="selectItem(item)" class="span" />
        </div>
        <div class="home_img">
          <img :src="item.item.productImage" alt />
        </div>
        <div class="home_name">{{item.item.productName}}</div>
        <div class="home_price">￥{{item.item.salePrice}}</div>
        <div class="home_button">
          <div class="home_button_one" @click="sub(item)">-</div>
          <div>{{item.count}}</div>
          <div class="home_button_one" @click="add(item)">+</div>
        </div>
        <div class="home_zojia">￥{{item.item.salePrice*item.count}}</div>
        <div class="home_sc" @click="del(index)">删除</div>
      </div>
    </div>
    <!-- 底部 -->
    <div class="home_footer">
      <div style="margin-left:20px;">
        <input type="checkbox" :checked="this.$store.state.allChecked" @click="allSelect" />全选
      </div>
      <div style="margin-right:20px;">总价:{{total}}</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {

    };
  },
  mounted() {
    this.$store.state.cartItem.map(ele => {
      ele.checked = true;
      if (ele.checked) {
        this.$store.state.total += ele.item.salePrice * ele.count;
        this.$store.state.allChecked = true;
      }
    });
  },
  methods: {
    // // 点击商品前面的商品的复选框
    selectItem(item) {
      this.$store.dispatch("SELECT_ITEM", item);
    },
    // // 点击底部的全选按钮
    allSelect() {
      this.$store.dispatch("ALLSELECT");
    },
    // // 减商品
    sub(item) {
      this.$store.dispatch("SUB_DATA", item);
    },
    // // 加商品
    add(item) {
      this.$store.dispatch("ADD_DATA", item);
    },
    // // 删除商品
    del(index) {
      this.$store.dispatch("DELETE", index);
    }
  },
  computed: {
    cartItem() {
      return this.$store.state.cartItem;
    },
    UnitPrice() {
      return this.$store.state.UnitPrice;
    },
    total() {
      return this.$store.state.total;
    }
  }
};
</script>

<style>
.Home_box {
  width: 100%;
  height: 100%;
}
.Home_list {
  width: 100%;
  height: 100px;
  border: 1px solid #eeeeee;
  display: flex;
  margin-top: 10px;
}
.home_check {
  flex: 0.3;
}
.home_check .span {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 1px solid gray;
  border-radius: 50%;
  margin-top: 35px;
  margin-left: 20px;
}
.home_img {
  flex: 0.6;
}
.home_img img {
  width: 85%;
  height: 100%;
  margin-left: 10px;
}
.home_name {
  flex: 1;
  text-indent: 10px;
  line-height: 100px;
}
.home_price {
  flex: 0.5;
  text-indent: 10px;
  line-height: 100px;
}
.home_button {
  flex: 1;
  display: flex;
  align-items: center;
}
.home_button_one {
  width: 20px;
  height: 20px;
  border: 1px solid #eeeeee;
  text-align: center;
  line-height: 20px;
  margin: 0 5px;
  background-color: white;
}
.home_zojia {
  flex: 1;
  line-height: 100px;
}
.home_sc {
  flex: 1;
  line-height: 100px;
}
.home_footer {
  width: 100%;
  height: 50px;
  border: 1px solid #eeeeee;
  background-color: white;
  position: fixed;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  line-height: 50px;
  font-size: 20px;
}
</style>